package com.china08.yxyapi.service.mg.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import com.china08.yxyapi.entity.mg.statistics.UserUploadResourceTotal;
import com.china08.yxyapi.repository.mg.statistics.UserUploadResourceTotalRepository;
import com.china08.yxyapi.service.mg.UserUploadResourceTotalService;
@Service
public class UserUploadResourceTotalServiceImpl implements UserUploadResourceTotalService {

	@Autowired
	private UserUploadResourceTotalRepository userUploadResourceTotalRepository;

	@Override
	public Page<UserUploadResourceTotal> getDataDetail(String schoolId, String resourceOrderList,
			String shareResOrderList, String weikeOrderList, String shareWeikeOrderList, String username,Pageable pageable) {
		Page<UserUploadResourceTotal> userUploadResourceTotal=null;
		if (resourceOrderList.equals("上传资源从高到低")) {
			userUploadResourceTotal=userUploadResourceTotalRepository.findBySchoolIdOrderByResCountDesc(schoolId,pageable);
			if(username!=null && !username.equals("")){
				userUploadResourceTotal=userUploadResourceTotalRepository.findBySchoolIdAndUserNickLikeOrderByResCountDesc(schoolId,username,pageable);
			}
		}else if(resourceOrderList.equals("上传资源从低到高")){
			userUploadResourceTotal=userUploadResourceTotalRepository.findBySchoolIdOrderByResCountAsc(schoolId,pageable);
			if(username!=null && !username.equals("")){
				userUploadResourceTotal=userUploadResourceTotalRepository.findBySchoolIdAndUserNickLikeOrderByResCountAsc(schoolId,username,pageable);
			}
		}else if(shareResOrderList.equals("共享资源从高到低")){
			userUploadResourceTotal=userUploadResourceTotalRepository.findBySchoolIdOrderByShareResCountDesc(schoolId,pageable);
			if(username!=null && !username.equals("")){
				userUploadResourceTotal=userUploadResourceTotalRepository.findBySchoolIdAndUserNickLikeOrderByShareResCountDesc(schoolId,username,pageable);
			}
		}else if(shareResOrderList.equals("共享资源从低到高")){
			userUploadResourceTotal=userUploadResourceTotalRepository.findBySchoolIdOrderByShareResCountAsc(schoolId,pageable);
			if(username!=null && !username.equals("")){
				userUploadResourceTotal=userUploadResourceTotalRepository.findBySchoolIdAndUserNickLikeOrderByShareResCountAsc(schoolId,username,pageable);
			}
		}else if(weikeOrderList.equals("上传微课从高到低")){
			userUploadResourceTotal=userUploadResourceTotalRepository.findBySchoolIdOrderByWeikeCountDesc(schoolId,pageable);
			if(username!=null && !username.equals("")){
				userUploadResourceTotal=userUploadResourceTotalRepository.findBySchoolIdAndUserNickLikeOrderByWeikeCountDesc(schoolId,username,pageable);
			}
		}else if(weikeOrderList.equals("上传微课从低到高")){
			userUploadResourceTotal=userUploadResourceTotalRepository.findBySchoolIdOrderByWeikeCountAsc(schoolId,pageable);
			if(username!=null && !username.equals("")){
				userUploadResourceTotal=userUploadResourceTotalRepository.findBySchoolIdAndUserNickLikeOrderByWeikeCountAsc(schoolId,username,pageable);
			}
		}else if(shareWeikeOrderList.equals("共享微课从高到低")){
			userUploadResourceTotal=userUploadResourceTotalRepository.findBySchoolIdOrderByShareWeikeCountDesc(schoolId,pageable);
			if(username!=null && !username.equals("")){
				userUploadResourceTotal=userUploadResourceTotalRepository.findBySchoolIdAndUserNickLikeOrderByShareWeikeCountDesc(schoolId,username,pageable);
			}
		}else if(shareWeikeOrderList.equals("共享微课从低到高")){
			userUploadResourceTotal=userUploadResourceTotalRepository.findBySchoolIdOrderByShareWeikeCountAsc(schoolId,pageable);
			if(username!=null && !username.equals("")){
				userUploadResourceTotal=userUploadResourceTotalRepository.findBySchoolIdAndUserNickLikeOrderByShareWeikeCountAsc(schoolId,username,pageable);
			}
		}else if(username!=null && !username.equals("")){
			userUploadResourceTotal=userUploadResourceTotalRepository.findBySchoolIdAndUserNickLike(schoolId,username,pageable);
		}
		
		if (userUploadResourceTotal==null) {
			userUploadResourceTotal=userUploadResourceTotalRepository.findBySchoolId(schoolId, pageable);
		}
		return userUploadResourceTotal;
	}

	
}
